<template>
  <input
    @keyup.enter="handleAdd"
    class="add"
    v-model="newTodo"
    type="text"
    placeholder="添加一项任务"
  />
</template>

<script>
export default {
  data() {
    return {
      newTodo: "",
    };
  },
  methods: {
    handleAdd() {
      if (this.newTodo.trim()) {
        this.$emit("add", this.newTodo);
        this.newTodo = "";
      } else {
        alert("请输入内容");
      }
    },
  },
};
</script>

<style>
</style>